#!/usr/bin/env bash
set -e
set -u
set -o pipefail


source "${BASH_SOURCE%/*}/assertions.sh"
source "${BASH_SOURCE%/*}/../src/site/build_site.sh"
source "${BASH_SOURCE%/*}/../src/main_function.sh"


test_build_main_mocked_including_some_coreutils() {
    source "${BASH_SOURCE%/*}/mocks/coreutils/cd"
    source "${BASH_SOURCE%/*}/mocks/coreutils/pwd"
    source "${BASH_SOURCE%/*}/mocks/fenrisg/get_absolute_path.sh"
    source "${BASH_SOURCE%/*}/mocks/fenrisg/get_date_stamp.sh"
    source "${BASH_SOURCE%/*}/mocks/fenrisg/get_git_branch.sh"
    source "${BASH_SOURCE%/*}/mocks/fenrisg/get_git_commit_id.sh"
    source "${BASH_SOURCE%/*}/mocks/fenrisg/get_git_commit_id_short.sh"
    source "${BASH_SOURCE%/*}/mocks/fenrisg/get_version.sh"
    source "${BASH_SOURCE%/*}/mocks/fenrisg/process_file.sh"
    build_site \
        "0" \
        "a" \
        "b" \
        "c" \
        "d" \
        "e" \
        "f" \
        > /dev/null
    assert_exit_status \
        "test_build_main_mocked_including_some_coreutils" \
        0 \
        $?
}


test_fenrisg_main_help() {
    source "${BASH_SOURCE%/*}/../src/usage.sh"
    fenrisg_main "-h" > /dev/null
    assert_exit_status \
        "test_build_main_version" \
        0 \
        $?
}


test_fenrisg_main_version() {
    source "${BASH_SOURCE%/*}/mocks/fenrisg/get_version.sh"
    fenrisg_main "-v" > /dev/null
    assert_exit_status \
        "test_build_main_version" \
        0 \
        $?
}


test_main_main() {
    test_build_main_mocked_including_some_coreutils
    test_fenrisg_main_help
    test_fenrisg_main_version
}


test_main_main
